﻿using FairyGUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public abstract class BasePopupPanel : BasePanel
{
    /// <summary>
    /// 窗体
    /// </summary>
    protected GComponent frame;

    /// <summary>
    /// 关闭动画
    /// </summary>
    protected Transition closeTransition;

    public override void Init()
    {
        base.Init();
        if (isClickClose())
        {
            view.onClick.Add(OnPanelClick);
        }
    }

    public override void Close()
    {
        if (closeTransition == null)
        {
            base.Close();
        }
        else
        {
            closeTransition.Play(OnComplete);
        }
    }

    private void OnComplete()
    {
        base.Close();
    }

    private void OnPanelClick(EventContext context)
    {
        GObject obj = GRoot.inst.touchTarget;
        if (frame != obj && !frame.IsAncestorOf(obj))
        {
            Close();
        }
    }

    /// <summary>
    /// 点击界面外范围关闭
    /// </summary>
    protected virtual bool isClickClose()
    {
        return true;
    }
}
